﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AsciiCreator
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                var img = new System.Drawing.Bitmap("smile.bmp");
                var file = new System.IO.StreamWriter("img.txt");

                const string GrayLevel = "@#8&o:*.  ";

                float brightness;
                for (int i = 0; i < img.Height; i = i + 5)
                {
                    for (int j = 0; j < img.Width; j = j + 3)
                    {
                        brightness = 0;
                        for (int k = i; k < i + 5 && k < img.Height; k++)
                        {
                            for (int l = j; l < j + 3 && l < img.Width; l++)
                            {
                                brightness += img.GetPixel(l, k).GetBrightness();
                            }
                        }
                        brightness = Math.Abs(brightness / 15 * 10 - 1);
                        file.Write(GrayLevel[Convert.ToInt16(brightness)]);
                    }
                    file.WriteLine();
                }
                file.Close();
            }
            catch
            {
                Console.WriteLine("Error ");
                Console.ReadLine();
            }
        }
    }
}
